package com.rtx.edi.platform.log.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rtx.api.annotation.DataSourceAnnotation;
import com.rtx.common.IdUtils;
import com.rtx.edi.model.log.po.PlApiRequestContentLog;
import com.rtx.edi.model.log.po.PlApiRequestLog;
import com.rtx.edi.platform.log.mapper.PlApiRequestContentLogMapper;
import com.rtx.edi.platform.log.mapper.PlApiRequestLogMapper;
import com.rtx.edi.platform.log.service.PlApiRequestContentLogService;

/**
 * <p>
 * api请求报文日志表  服务实现类
 * </p>
 *
 * @author wq
 * @since 2023-03-14
 */
/**
 * 代码迁移至com.rtx.edi.auth.log
 * @author A
 *
 */
@Service
public class PlApiRequestContentLogServiceImpl extends ServiceImpl<PlApiRequestContentLogMapper, PlApiRequestContentLog> implements PlApiRequestContentLogService {

	Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	PlApiRequestLogMapper plApiRequestLogMapper;
	
    @Override
    public PlApiRequestContentLog selectplApiRequestContentLogByLogNo(String logNo) {
        LambdaQueryWrapper<PlApiRequestContentLog> query = new LambdaQueryWrapper<>();
        query.eq(PlApiRequestContentLog::getLogNo,logNo);
        return baseMapper.selectOne(query);
    }

    @DataSourceAnnotation
	@Override
	public void inserRtxLog(String datasourckey,PlApiRequestContentLog content, PlApiRequestLog log) {
		try {
			String logno = IdUtils.simpleUUID();
			//记录日志
			log.setLogNo(logno);
			content.setLogNo(logno);
			
			baseMapper.insert(content);
			plApiRequestLogMapper.insert(log);
		} catch (Exception e) {
			logger.error("奇门请求记录日志异常-",e);
		}
		
	}
}
